package com.meiborte.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.meiborte.mapper.ItemMapper;
import com.meiborte.pojo.Item;
import com.meiborte.service.ItemService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ItemServiceImpl implements ItemService {
    @Resource
    ItemMapper itemMapper;

    @Override
    public Item selectById(Integer id) {
        return itemMapper.selectById(id);
    }

    @Override
    public List<Item> selectAll() {
        return itemMapper.selectList(null);
    }

    @Override
    public List<Item> selectByType(String type) {
        QueryWrapper<Item> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Item::getType, type);
        return itemMapper.selectList(queryWrapper);
    }

    @Override
    public void deleteById(Integer id) {
        itemMapper.deleteById(id);
    }

    @Override
    public Item insert(Item item) {
        itemMapper.insert(item);
        return item;
    }

    @Override
    public Item updateById(Item item) {
        itemMapper.updateById(item);
        return item;
    }
}
